/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import { TurboModuleRegistry } from 'react-native';

export enum AvoidAreaType { TYPE_SYSTEM, TYPE_CUTOUT, TYPE_SYSTEM_GESTURE, TYPE_KEYBOARD, TYPE_NAVIGATION_INDICATOR };

export interface AvoidAreaOptions {
  type: AvoidAreaType;
  area: AvoidArea;
}

export interface Rect {
  left: number; // 矩形区域的左边界，单位为px，该参数为整数。
  top: number; // 矩形区域的上边界，单位为px，该参数应为整数。
  width: number; // 矩形区域的宽度，单位为px，该参数应为整数。
  height: number; // 矩形区域的高度，单位为px，该参数应为整数。
}

export interface AvoidArea {
  visible: boolean; // 规避区域是否可见。true表示可见；false表示不可见。
  leftRect: Rect; // 屏幕左边的矩形区。
  topRect: Rect; // 屏幕上边的矩形区。
  rightRect: Rect; // 屏幕右边的矩形区。
  bottomRect: Rect; // 屏幕下边的矩形区。
}

export interface Spec extends TurboModule {
  getWindowAvoidArea(type: number): AvoidArea;
  addAvoidAreaListener(): void;
  removeAvoidAreaListener(): void;
}

export default TurboModuleRegistry.get<Spec>(
  'RTNAvoidAreaRegion',
) as Spec | null;